package com.edu.order.controller;


import com.edu.entity.HfdLocInfo;
import com.edu.entity.HfdOrderInfo;
import com.edu.order.entity.OrderPage;
import com.edu.order.service.IHfdLocInfoService;
import com.edu.order.service.IHfdOrderInfoService;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author lc
 * @since 2021-04-13
 */
@RestController
@RequestMapping("/order")
public class HfdOrderInfoController {

    @Autowired
    private IHfdOrderInfoService hfdOrderInfoService;

    //生成保存订单
    @RequestMapping("save")
    public Result save(@RequestBody OrderPage orderPage){
        return hfdOrderInfoService.order(orderPage);
    }

    //超时订单修改状态
    @RequestMapping("releaseOrder")
    public Result releaseOrder(String orderId){
        return hfdOrderInfoService.releaseOrder(orderId);
    }

    //订单页面课程数据数据初始化
    @RequestMapping("orderPage")
    public Result orderPage(Integer skuId){
        return hfdOrderInfoService.orderPage(skuId);
    }

    //根据orderId查询订单
    @RequestMapping("findOrderById")
    public HfdOrderInfo findOrderById(String orderId){
        return hfdOrderInfoService.findOrderById(orderId);
    }

    //修改订单状态
    @RequestMapping("update")
    public Result update(@RequestBody HfdOrderInfo hfdOrderInfo){

        boolean b = hfdOrderInfoService.updateById(hfdOrderInfo);

        return new Result(b,b?70041:70040,b?"success":"fail");

    }

    //购买成功后添加用户_课程中间表
    @RequestMapping("addUserVideo")
    public Result addUserVideo(@RequestBody HfdOrderInfo hfdOrderInfo){
        return hfdOrderInfoService.addUserVideo(hfdOrderInfo);
    }



}
